package com.yikaiye.android.yikaiye.dialog;

import android.content.Context;
import android.view.inputmethod.InputMethodManager;

import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.databinding.DialogVerifyPhoneNumberBinding;
import com.yikaiye.android.yikaiye.utils.CommonUtil;
import com.yikaiye.android.yikaiye.widget.CountDownTextView;

/**
 * 验证手机号码
 */
public class VerifyPhoneNumberDialog extends BaseCommonBottomDialog<DialogVerifyPhoneNumberBinding> {

    private final Context context;
    private String phone;

    public VerifyPhoneNumberDialog(Context context, String phone) {
        super(context);
        this.context = context;
        this.phone = phone;
    }

    @Override
    protected void initView() {
        // 弹窗显示同时键盘弹出
        mBinding.codeEt.postDelayed(() -> {
            mBinding.codeEt.requestFocus();
            InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
            inputMethodManager.showSoftInput(mBinding.codeEt, 0);
        }, 200);

        mBinding.phoneTv.setText(CommonUtil.getEncryptPhone(phone));
        mBinding.closeIv.setOnClickListener(view -> dismiss());

        mBinding.codeEt.setOnTextChangeListener((text, isComplete) -> {
            mBinding.mergeNowTv.setBackgroundResource(isComplete ? R.drawable.shape_f93f50_4dp : R.drawable.shape_33f93f50_4dp);
            mBinding.mergeNowTv.setEnabled(isComplete);
        });

        mBinding.getCodeTv.setOnClickListener(view -> getCode(mBinding.getCodeTv));

        mBinding.mergeNowTv.setOnClickListener(view -> {
            verifyNow(mBinding.codeEt.getText().toString());
            dismiss();
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_verify_phone_number;
    }


    public void verifyNow(String smsCode) {

    }

    public void getCode(CountDownTextView codeTv) {

    }
}
